--Delete database neu da ton tai.
USE master
GO

IF EXISTS(SELECT name FROM sys.databases WHERE name = 'WF_LINH') 
DROP DATABASE WF_LINH 
GO

--Create database IMPRO.
CREATE DATABASE WF_LINH
GO

USE WF_LINH
GO

--01. Table Departments
CREATE TABLE Departments
(
	DEPTNO		NVARCHAR(10) CONSTRAINT PK_DEPTNO PRIMARY KEY,
	DEPTNAME	NVARCHAR(50),
)
GO

--02. Table Designation
CREATE TABLE Designation
(
	DESIGNID	NVARCHAR(10)	CONSTRAINT PK_DESIGNID PRIMARY KEY,
	DESIGNATION	NVARCHAR(20)
)
GO

--03. Table Employees
CREATE TABLE Employees
(
	EMPROWINDEX		INT,
	EMPID		NVARCHAR(10)	CONSTRAINT PK_EMPID PRIMARY KEY,
	EMPNAME		NVARCHAR(20),
	DEPTNO		NVARCHAR(10)	CONSTRAINT FK_Emp_DEPTNO FOREIGN KEY REFERENCES Departments(DEPTNO),
	DESIGNID	NVARCHAR(10)	CONSTRAINT FK_Emp_DESGID FOREIGN KEY REFERENCES Designation(DESIGNID),
	EMPBIRTHDAY DATETIME,
	EMPSALARY	INT,
)
GO

Insert into Departments values('D001','Maketing')
Insert into Departments values('D002','Factory')
Insert into Departments values('D003','Warehouse')
Insert into Departments values('D004','Office')

Insert into Designation values('DE01','Manager')
Insert into Designation values('DE02','Programer')
Insert into Designation values('DE03','Staff Office')
Insert into Designation values('DE04','Director')

Insert Into Employees values (1,'E001','linh','D001','DE01','4/30/1991',2000000)
Insert Into Employees values (2,'E002','duy','D002','DE03','7/22/1992',3000000)
Insert Into Employees values (3,'E003','kiet','D003','DE01','1/14/1999',2500000)
Insert Into Employees values (4,'E004','dang','D004','DE02','9/17/1991',1000000)
Insert Into Employees values (5,'E005','TEST1','D002','DE03','11/28/1993',4000000)
Insert Into Employees values (6,'E006','TEST2','D004','DE04','6/20/1998',5500000)
Insert Into Employees values (7,'E007','TEST4','D002','DE04','12/1/1997',1000000)
Insert Into Employees values (8,'E008','TEST3','D003','DE02','3/5/1990',1500000)

SELECT * FROM Departments 
SELECT * FROM Designation 
SELECT * FROM Employees 
